package com.dolphin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dolphin.commons.DateUtils;
import com.dolphin.commons.Pager;
import com.dolphin.mapper.NoticeMapper;
import com.dolphin.model.Notice;
import com.dolphin.service.NoticeService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 描述:
 * ${DESCRIPTION}
 *
 * @author 林平
 * @create 2022-09-06 23:10
 * 个人博客地址：https://www.nonelonely.com
 */
@Service
public class NoticeServiceImpl extends ServiceImpl<NoticeMapper, Notice> implements NoticeService {


    public Pager<Notice> list(Pager<Notice> pager) {
        PageHelper.startPage(pager.getPageIndex(), pager.getPageSize());
        QueryWrapper<Notice> userQueryWrapper = new QueryWrapper<>(pager.getForm());
        List<Notice> categories = this.list(userQueryWrapper);
        PageInfo<Notice> pageInfo = new PageInfo<>(categories);
        pager.setTotal(pageInfo.getTotal());
        pager.setData(pageInfo.getList());
        pager.setCode(Pager.SUCCESS_CODE);
        return pager;
    }

    @Override
    public List<Notice> listNotices() {
        QueryWrapper<Notice> userQueryWrapper = new QueryWrapper<>();
        userQueryWrapper.ge("over_time", DateUtils.getNowDate());
        List<Notice> categories = this.list(userQueryWrapper);
        return categories;
    }

}
